package dialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.example.zx.theline.R;
import com.example.zx.theline.jclr.pub.ZsrjhtxjdjcActivity;

import java.util.List;

import Utils.DensityUtil;
import base.BaseDialog;
import views.MoreItem;

/**
 * Created by Ren on 2017/6/5.
 */

public class MoreDialog extends BaseDialog {

    LinearLayout body;

    View.OnClickListener listener;

    MoreItem searchItem;

    MoreItem addCheckItem;

    public MoreDialog(Context context,View.OnClickListener listener) {
        super(context);
        this.listener=listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_more);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {
        //设置dialog背景为透明
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        //添加in out 动画
        getWindow().setWindowAnimations(R.style.anim_scale_right_top);

        //使用带箭头的图片做背景
        body = (LinearLayout) findViewById(R.id.body);
        body.setBackgroundResource(R.drawable.dialog_bk);

        //所有的用户 都具有seach权限
        searchItem = new MoreItem(getContext(), "分类查询", R.drawable.search_click, new MoreItem.MoreItemClickLinten() {
            @Override
            public void moreItemClickLinten() {
               listener.onClick(searchItem);
            }
        });

        body.addView(searchItem);

        //所有用户都具有新增检查单的权限
         addCheckItem = new MoreItem(getContext(), "检查录入", R.drawable.add_item, new MoreItem.MoreItemClickLinten() {
            @Override
            public void moreItemClickLinten() {
                Intent mIntent=new Intent(getContext(), ZsrjhtxjdjcActivity.class);
                getContext().startActivity(mIntent);
                MoreDialog.this.dismiss();
            }
        });
        body.addView(addCheckItem);
    }


    @Override
    protected void InitData() {

    }

    @Override
    protected void InitListen() {

    }

    public void setItem(List<View> viewList) {
        //如果没有设置数据源，那么有一个默认标题
        if (viewList.size() != 0) {
            for (int i = 0; i < viewList.size(); i++) {
                body.addView(viewList.get(i));
            }
        }
    }

    @Override
    public void show() {
        super.show();
        Window dialogwindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogwindow.getAttributes();
        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity=Gravity.TOP|Gravity.RIGHT;
        lp.y=DensityUtil.dip2px(getContext(),35);
        lp.x=DensityUtil.dip2px(getContext(),10);

        dialogwindow.setAttributes(lp);
        this.setCanceledOnTouchOutside(true);
    }



}
